package util;

import java.io.Closeable;
import java.io.IOException;
import java.net.Socket;
import java.util.Date;

/**
 * @author Karl
 * @Date 2023/1/1 - 23:28
 */
public class MyUtil {
    private MyUtil(){}

    /**
     * IO操作中共同的关闭方法
     *
     * @param closeable
     */
    public static void closeIo(Closeable closeable) {
        if (null != closeable) {
            try {
                closeable.close();
            } catch (IOException ignore) {
            }
        }
    }

    /**
     * IO操作中共同的关闭方法
     *
     * @param closeable
     */
    public static void closeIo(Socket closeable) {
        if (null != closeable) {
            try {
                closeable.shutdownOutput();
                closeable.close();
            } catch (IOException ignore) {
            }
        }
    }


    //格式化打印方法，用来打印信息
    public static void log(Object message, Object... args) {
        try {
            Date dat = new Date();
            String msg = String.format("%1$tF %1$tT %2$-5s %3$s%n", dat, Thread.currentThread().getId(), String.format(message.toString(), args));
            System.out.print(msg);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
